package algorithm.sort;

import struct.advanced.heap.MaxHeap;

/**
 * @author MAX
 * @version 1.0
 * @description 排序算法-堆排序
 * @date 2022/1/22 16:56
 */
public class HeapSort {

    private HeapSort(){}

    public static <E extends Comparable<E>> void sort(E[] data) {
        MaxHeap<E> maxHeap = new MaxHeap<>(data);
        /*for (E e : data) {
            maxHeap.add(e);
        }*/

        /*MaxHeap<E> maxHeap = new MaxHeap<>();
        for (E e : data) {
            maxHeap.add(e);
        }*/

        //asc order
        for (int i = data.length - 1; i >= 0; i--) {
            data[i] = maxHeap.extractMax();
        }
    }
}
